import type {ActionType} from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { PageContainer } from '@ant-design/pro-layout';
import {Button} from "antd";
import {PlusOutlined} from "@ant-design/icons";
import {useRef} from "react";
import { seckillList} from "@/services/ant-design-pro/marketing";


export default () => {
  const actionRef = useRef<ActionType>();

  const columns = [
    {
      dataIndex: 'seckill_id',
      width: 100,
      title: '商品ID',
      search: false,
      align: 'center',
    },
    {
      title: '优惠券名称',
      dataIndex: 'title',
      align: 'center',
      width: 200,
    },
    {
      title: '开始时间',
      dataIndex: 'created_at',
      search: false,
      align: 'center',

    },
    {
      title: '秒杀金额',
      dataIndex: 'seckill_price',
      search: false,
      align: 'center',
    },
    {
      title: '最多秒杀个数',
      dataIndex: 'num',
      search: false,
      align: 'center',
    },
    {
      title: '结束时间',
      dataIndex: 'updated_at',
      search: false,
      align: 'center',
    },

    {
      title: '状态',
      dataIndex: 'status',
      valueType: 'select',
      align: 'center',
      valueEnum: {
        participating: '进行中',
        endOfActivitySuccess: '已成功',
        endOfActivityFail: '已失败',
      }
    },
    {
      title: '操作',
      valueType: 'option',
      align: 'center',
      fixed: 'right',
      width: 200,
      render: (_, record) => [
        <a
          onClick={() => {
          }}
        >
          秒杀详情
        </a>,
      ],
    },
  ];


  return (
    <PageContainer
      header={{
        breadcrumb: {},
      }}
    >

      <ProTable
        columns={columns}
        actionRef={actionRef}
        request={async (params)=>{
          const {data,meta} =  await seckillList({...params})
          return{
            data,
            success:true,
            total:meta.pagination.total
          }
        }}
        editable={{
          type: 'multiple',
        }}
        rowKey="id"
        search={{
          labelWidth: 'auto',
        }}
        scroll={{ x: 1400 }}
        form={{
          // 由于配置了 transform，提交的参与与定义的不同这里需要转化一下
          syncToUrl: (values, type) => {
            if (type === 'get') {
              return {
                ...values,
                created_at: [values.startTime, values.endTime],
              };
            }
            return values;
          },
        }}
        pagination={{
          pageSize: 10,
        }}
        dateFormatter="string"
        toolBarRender={() => [
          <Button
            type="primary"
            onClick={() => {
            }}
            icon={<PlusOutlined />}
          >
            添加秒杀商品
          </Button>
        ]}
      />



    </PageContainer>

  );
};
